package com.cyy.i.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Author: Cyy
 * @Description: jdk动态代理类
 * @Date:Created in 17:15 2018/7/19
 */
public class DynamicUserDaoProxy {

    private Object target;

    public DynamicUserDaoProxy(Object target) {
        this.target = target;
    }

    public Object getProxyInstance(){
        return Proxy.newProxyInstance(
                target.getClass().getClassLoader(),
                target.getClass().getInterfaces(),
                new InvocationHandler(){
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("执行目标事务前的操作。。。");
                        Object returnValue=method.invoke(target,args);
                        System.out.println("执行目标事务后的操作。。。");
                        return returnValue;
                    }
                });
    }

}
